<?php


class AppConfigPlugin {

	
	/**
	 * Retorna el objeto Menu con sus propiedades seteadas
	 */
	public static function getMenuItems() {
		require('conf/configuration.php');
		return $menuItems;
		
	}
	
	
	/**
	 * Retorna el objeto Manage con sus propiedades seteadas
	 */
	public static function getManageItems() {
		require('conf/configuration.php');
		return $manageItems;
		
	}

	
	
	/**
	 * Retorna app info
	 */
	public static function getAppInfo() {
		require('conf/configuration.php');
		return $appInfo;
	}
	
	

	public static function search($array, $script, &$breadcrumb, &$found) {
		set_time_limit(0);
		for($i = 0; $i <= count($array) && !$found; $i++) {
			$item = $array[$i];
			if ($item[script] == $script) {
				$breadcrumb[] = array("name" => $item[name], "script" => $item[script], "image" => $item[image]);
				$found = true;
			} else {
				if (($item[sons] != null) && (count($item[sons]) > 0)) {
					$breadcrumb[] = array("name" => $item[name], "script" => $item[script]);
					$found = AppConfigPlugin::search($item[sons], $script, $breadcrumb, $found);
					if (!$found)
						array_pop($breadcrumb);
				}
			}
		}
		return $found;
	}
	
	/**
	 * Retorna page tree
	 */
	public static function getBreadcrumb($script) {
		require('conf/configuration.php');
		$found = false;
		set_time_limit(0);
		$breadcrumb = array(); 
		$exist = AppConfigPlugin::search($pageTree, $script, $breadcrumb, $found);
		return $breadcrumb;
	}
	
	
	
	public static function sons($array, $script, &$sons, &$found) {
		set_time_limit(0);
		for($i = 0; $i <= count($array) && !$found; $i++) {
			$item = $array[$i];
			if ($item[script] == $script) {
				$sons = $item[sons];
				$found = true;
			} else {
				if (($item[sons] != null) && (count($item[sons]) > 0)) {
					//$breadcrumb[] = array("name" => $item[name], "script" => $item[script]);
					$found = AppConfigPlugin::sons($item[sons], $script, $sons, $found);
					/*if (!$found)
						array_pop($breadcrumb);*/
				}
			}
		}
		return $found;
	}
	

	/**
	 * Retorna page tree
	 */
	public static function getSons($script) {
		require('conf/configuration.php');
		$found = false;
		set_time_limit(0);
		$sons = array(); 
		$exist = AppConfigPlugin::sons($pageTree, $script, $sons, $found);
		return $sons;
	}
	
	
}